"use strict";

const errorOverlayMiddleware = require("react-dev-utils/errorOverlayMiddleware");
const noopServiceWorkerMiddleware = require("react-dev-utils/noopServiceWorkerMiddleware");
const path = require("path");
const config = require("./webpack.config.dev");
const paths = require("./paths");

const protocol = process.env.HTTPS === "true" ? "https" : "http";
const host = process.env.HOST || "0.0.0.0";

module.exports = function (proxy, allowedHost) {
  return {
    // 表示允许跨域
    headers: {
      "Access-Control-Allow-Origin": "*", 
    },
    
    disableHostCheck:
      !proxy || process.env.DANGEROUSLY_DISABLE_HOST_CHECK === "true",

    compress: true,
    clientLogLevel: "none",
    contentBase: paths.appPublic,
    watchContentBase: true,
    hot: true,
    publicPath: config.output.publicPath,

    quiet: true,

    watchOptions: {
      ignored: new RegExp(
        `^(?!${path
          .normalize(paths.appSrc + "/")
          .replace(/[\\]+/g, "\\\\")}).+[\\\\/]node_modules[\\\\/]`,
        "g"
      ),
    },
    // Enable HTTPS if the HTTPS environment variable is set to 'true'
    https: protocol === "https",
    host: host,
    overlay: false,
    historyApiFallback: {
      disableDotRule: true,
    },
    public: allowedHost,
    proxy,
    before(app) {
      app.use(errorOverlayMiddleware());

      app.use(noopServiceWorkerMiddleware());
    },
  };
};
